<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('dashBoard.no2')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('dashBoard.no3')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- -------------搜索查询栏------------------------ -->
    <search 
      :searchData="searchData" 
      @search="search" 
      :searchRight="true"
    ></search>
    
    <div class="list_operation" v-if="$store.state.common.permiss.merchantlist.includes('add')">
      <el-button 
        type="primary"  
        size="small"
        @click="jumpDetail(null)">{{$t('merchantList.no7')}}</el-button>
    </div>

    <!-- -------------表格数据开始------------------------ -->
    <!-- <div class="table" v-if="$store.state.common.permiss.includes('RIGHT_ACCOUNT_LENDING_LIST')"> -->
    <div class="table">
      <template>
        <el-table :data="tableData" stripe size="small" >
          <el-table-column align="center" prop="partnerNo" :label="$t('merchantList.no8')"></el-table-column>
          <el-table-column align="center" prop="partnerName" :label="$t('merchantList.no1')"></el-table-column>
          <el-table-column align="center" prop="contactName" :label="$t('merchantList.no2')"></el-table-column>
          <el-table-column align="center" prop="contactPhone" :label="$t('merchantList.no3')"></el-table-column>
          <el-table-column align="center" prop="trackerAdminName" :label="$t('merchantList.no9')"></el-table-column>
          <el-table-column align="center" prop="createTime" :label="$t('merchantList.no6')"></el-table-column>
          <el-table-column align="center" prop="stage" :label="$t('merchantList.no4')">
            <template slot-scope="scope">{{$t($store.getters.merchantList_options(scope.row.stage))}}</template>
          </el-table-column>
          <el-table-column align="center" prop="appOnlineTime" :label="$t('merchantList.no10')"></el-table-column>
          <el-table-column align="center" prop="cooperationTimeStart" :label="$t('merchantList.no11')">
            <template slot-scope="scope">{{scope.row.cooperationTimeStart?`${scope.row.cooperationTimeStart}~${scope.row.cooperationTimeEnd}`:'-'}}</template>
          </el-table-column>
          <el-table-column fixed="right" align="center" prop="operation" :label="$t('public.operation')" min-width="210">
            <template slot-scope="scope" >
              <!-- 查看编辑 -->
              <span v-if="$store.state.common.permiss.merchantlist.includes('view')" class="table_opr" @click="jumpDetail(scope.row.id)">{{$t('merchantList.no12')}}</span>
              <!-- 注销 -->
              <template v-if="$store.state.common.permiss.merchantlist.includes('cancel')">
                <span  class="table_opr" v-if="scope.row.stage!=0"  @click="showdel(scope.row.id,scope.row.partnerName)">{{$t('merchantList.no13')}}</span>
                <span v-else style="margin:0 5px">{{$t('merchantList.no13')}}</span>
              </template>
              <!-- 合同下载 -->
              <template v-if="$store.state.common.permiss.merchantlist.includes('download')">
                <span v-if="scope.row.agreementUrl" class="table_opr" @click="downHerf(scope.row.agreementUrl)">{{$t('merchantList.no14')}}</span>
                <span v-else style="margin:0 5px">{{$t('merchantList.no14')}}</span>
              </template>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- ------------  分页显示栏  ------------------------ -->
    <el-row type="flex" justify="end">
      <div class="pages" >
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          layout="sizes, prev, pager, next, total,->"
          :page-sizes="pagination.pageSizeOptions"
          :page-size="pagination.pageSize"
          @size-change="handleSizeChange"
          :total="pagination.total">
        </el-pagination>
      </div>
    </el-row>

    <!-- 注销弹窗 -->
    <el-dialog :title="$t('OutsourcedManage.no13')" :visible.sync="delFlag"  width="560px">
      <p>{{$t('merchantList.no56')}} <span class="blue">{{partnerName}}</span> ?</p>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closedel()">{{$t('public.no50')}}</el-button>
        <el-button type="primary" @click="delSure()">{{$t('public.no49')}}</el-button>
      </span>
    </el-dialog>

    <div class="foot"></div>

  </div>
</template>
<script>
export default {
  name: 'merchantList',
  data () {
    const searchData=[
      {
        type: 'input',
        label: 'merchantList.no1',
        attr: 'partnerName',
        value: ''
      },{
        type: 'input',
        label: 'merchantList.no2',
        attr: 'contactName',
        value: ''
      },{
        type: 'input',
        label: 'merchantList.no3',
        attr: 'contactPhone',
        value: ''
      },{
        type: 'select',
        label: 'merchantList.no4',
        attr: 'stage',
        option: this.$store.state.options.merchantListStatus_option,
        value: '',
        langFlag: true,
      },
      // {
      //   type: 'select',
      //   label: 'merchantList.no5',
      //   attr: 'trackerAdminId',
      //   option: [],
      //   value: '',
      //   langFlag: true,
      // },
      {
        type: 'rangePicker',
        label: 'merchantList.no6',
        attr: 'createTime',
        value: [],
      }]
    return {
      flag: true,
      loadFlag: true,
      delFlag: false,
      delId: '',
      partnerName: '',
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      searchData:searchData,
      formInline: {},// 用户查询信息数据对应字段
      tableData: [],// 表格数据
    }
  },
  methods: {
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.getTableData();
    },
    search(search) { // 搜索
      this.formInline = {
        partnerName: search.partnerName,
        contactName: search.contactName,
        contactPhone:search.contactPhone,
        trackerAdminId: search.trackerAdminId,
        stage: search.stage,
        createTimeStart: search.createTime?search.createTime[0]:'',
        createTimeEnd: search.createTime?search.createTime[1]:'',
      };
      this.pagination.current = 1;
      this.getTableData();
    },
    getTableData () { // 列表数据获取
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.partner_list, option).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.tableData.forEach(value=>{
            value.visible = false
          })
          this.pagination.total = res.data.total;
        }else {
          this.$globalMsg.error(res.message)
        }
        this.loadFlag = false;
      })
    },
    jumpDetail(id){
      if(id){
        this.$router.push({path: '/addmerchant', query: {id,from:'merchant'}})
      }else {
        this.$router.push({path: '/addmerchant',query: {from:'merchant'}})
      }
    },
    downHerf(href){
      if(href){
        window.location.href = href
        // let option = {
        //   param: href
        // }
        // this.$axios.get(this.$action.fileDownload+'?path='+href).then(res => {
        //   if (res.code == 200) {
            
        //   }
        // })
      }
    },
    showdel(id,name){
      this.delId = id
      this.partnerName = name
      this.delFlag = true
    },
    closedel(){
      this.delFlag = false
    },
    delSure(){// 删除商户确定
      let option = {
        param: {
          id: this.delId
        }
      }
      this.$axios.post(this.$action.partner_delete, option).then(res => {
        if (res.code == 200) {
          this.$globalMsg.success(this.$t('message.success'))
          this.getTableData()
          this.closedel()
        }else{
          this.$globalMsg.error(res.message)
        }
      })
    }
  },
  mounted () {
    this.getTableData();
  }
}
</script>
<style scoped lang="scss">

</style>
